<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col :span="6" :xs="24">
        <el-card class="box-card" shadow="hover">
          <div slot="header" class="clearfix">
            <span class="card-header">个人信息</span>
          </div>
          <div class="profile-info">
            <div class="text-center mb-3">
              <userAvatar :user="user" />
            </div>
            <ul class="list-group list-group-striped">
              <li class="list-group-item">
                <svg-icon icon-class="user" />
                用户名称
                <div class="pull-right">{{ user.nickname }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="date" />
                最后登录时间
                <div class="pull-right">
                  {{ new Date(user.lastLoginTime).toLocaleString() }}
                </div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="date" />
                注册时间
                <div class="pull-right">
                  {{ new Date(user.createTime).toLocaleString() }}
                </div>
              </li>
            </ul>
          </div>
        </el-card>
      </el-col>
      <el-col :span="18" :xs="24">
        <el-card class="box-card" shadow="hover">
          <el-tabs
            v-model="activeTab"
            tab-position="left"
            class="tabs-container"
          >
            <el-tab-pane label="基本资料" name="userinfo">
              <span slot="label"
                ><i class="el-icon-user-solid"></i> 基本资料</span
              >
              <userInfo :user="user" />
            </el-tab-pane>
            <el-tab-pane label="我的收藏" name="MyCollect">
              <span slot="label"
                ><i class="el-icon-collection-tag"></i> 我的收藏</span
              >
              <el-button type="danger" class="mb-3" size="mini" @click="close"
                >关闭</el-button
              >
              <el-tabs type="border-card" class="sub-tabs">
                <el-tab-pane label="電影">
                  <userCollect table-name="wm_movie"></userCollect>
                </el-tab-pane>
                <el-tab-pane label="博客">
                  <userCollect table-name="blog_article"></userCollect>
                </el-tab-pane>
                <el-tab-pane label="演员">
                  <userCollect table-name="wm_actor"></userCollect>
                </el-tab-pane>
                <el-tab-pane label="问答">
                  <userCollect table-name="qa_question"></userCollect>
                </el-tab-pane>
              </el-tabs>
            </el-tab-pane>
            <el-tab-pane label="修改密码" name="resetPwd">
              <span slot="label"><i class="el-icon-s-tools"></i> 修改密码</span>
              <resetPwd :user="user" />
            </el-tab-pane>
          </el-tabs>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import userAvatar from './userAvatar'
import userInfo from './userInfo'
import resetPwd from './resetPwd'
import userCollect from './userCollect'
import { getUserProfile } from '@/api/system/user'

export default {
  name: 'Profile',
  components: { userAvatar, userInfo, resetPwd, userCollect },
  data() {
    return {
      user: {},
      activeTab: 'userinfo',
    }
  },
  created() {
    this.getUser()
  },
  methods: {
    close() {
      this.$router.push({ path: '/' })
    },
    getUser() {
      getUserProfile().then(response => {
        this.user = response.data
      })
    },
  },
}
</script>

<style scoped>
.app-container {
  margin: auto;
  padding: 20px;
  background-color: #f5f7fa;
}

.card-header {
  color: #409eff;
  font-weight: bold;
  font-size: 18px;
}

.profile-info .list-group {
  padding-left: 0px;
  list-style: none;
}

.profile-info .list-group-item {
  margin-bottom: 10px;
  padding: 12px;
  border: 1px solid #e0e6ed;
  border-radius: 8px;
  background-color: #ffffff;
  font-size: 14px;
}

.profile-info .list-group-item:hover {
  background-color: #f4f7fa;
}

.pull-right {
  float: right !important;
  color: #666;
}

.el-card {
  border-radius: 8px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.el-tabs__nav {
  margin-top: 10px;
}

.el-tabs__nav .el-tab {
  padding: 10px 15px;
  font-size: 14px;
}

.el-tabs__nav .is-active {
  color: #409eff;
  font-weight: bold;
}

.sub-tabs .el-tab-pane {
  padding: 10px;
}

.mb-3 {
  margin-bottom: 16px;
}

.tabs-container {
  padding: 15px;
  border-radius: 8px;
  background-color: #ffffff;
}

.el-button.danger {
  border-color: #f56c6c;
  background-color: #f56c6c;
  color: white;
}

.el-button.danger:hover {
  border-color: #f46666;
  background-color: #f46666;
}

.el-card.shadow-hover:hover {
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}
</style>
